lib/repo-refs: Allow resolving local collection-refs
authorMatthew Leeds <matthew.leeds@endlessm.com>
Thu, 21 Feb 2019 23:47:16 +0000 (15:47 -0800)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 15 Apr 2019 15:56:40 +0000 (15:56 +0000)
Currently for a "normal" refspec you can choose to use
ostree_repo_resolve_rev_ext() instead of ostree_repo_resolve_rev() if
you only want to look at local refs (in refs/heads/) not remote ones.
This commit provides the analogous functionality for
ostree_repo_resolve_collection_ref() by adding a flag
OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY and implementing it. This
will be used by Flatpak.

Closes: #1825
Approved by: jlebon

src/libostree/ostree-repo-refs.c
src/libostree/ostree-repo.h

index fec36420c9a0bbbaab25bf0b05a2b5a0ddbb8849..c512787a18d3ebedd84c21a1f67ac71e2cc46ac3 100644 (file)
@@ -479,6 +479,9 @@ ostree_repo_resolve_rev (OstreeRepo     *self,
  * the parameter @out_rev. Differently from ostree_repo_resolve_rev(),
  * this will not fall back to searching through remote repos if a
  * local ref is specified but not found.
+ *
+ * The flag %OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY is implied so
+ * using it has no effect.
  */
 gboolean
 ostree_repo_resolve_rev_ext (OstreeRepo                    *self,
@@ -511,7 +514,9 @@ ostree_repo_resolve_rev_ext (OstreeRepo                    *self,
  * the given @ref cannot be found, a %G_IO_ERROR_NOT_FOUND error will be
  * returned.
  *
- * There are currently no @flags which affect the behaviour of this function.
+ * If you want to check only local refs, not remote or mirrored ones, use the
+ * flag %OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY. This is analogous to using
+ * ostree_repo_resolve_rev_ext() but for collection-refs.
  *
  * Returns: %TRUE on success, %FALSE on failure
  * Since: 2018.6
@@ -539,7 +544,16 @@ ostree_repo_resolve_collection_ref (OstreeRepo                    *self,
     {
       g_mutex_lock (&self->txn_lock);
       if (self->txn.collection_refs)
-        ret_contents = g_strdup (g_hash_table_lookup (self->txn.collection_refs, ref));
+        {
+          const char *repo_collection_id = ostree_repo_get_collection_id (self);
+          /* If the collection ID doesn't match it's a remote ref */
+          if (!(flags & OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY) ||
+              repo_collection_id == NULL ||
+              g_strcmp0 (repo_collection_id, ref->collection_id) == 0)
+            {
+              ret_contents = g_strdup (g_hash_table_lookup (self->txn.collection_refs, ref));
+            }
+         }
       g_mutex_unlock (&self->txn_lock);
     }
 
@@ -547,9 +561,15 @@ ostree_repo_resolve_collection_ref (OstreeRepo                    *self,
   if (ret_contents == NULL)
     {
       g_autoptr(GHashTable) refs = NULL;  /* (element-type OstreeCollectionRef utf8) */
+      OstreeRepoListRefsExtFlags list_refs_flags;
+
+      if (flags & OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY)
+        list_refs_flags = OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES | OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS;
+      else
+        list_refs_flags = OSTREE_REPO_LIST_REFS_EXT_NONE;
+
       if (!ostree_repo_list_collection_refs (self, ref->collection_id, &refs,
-                                             OSTREE_REPO_LIST_REFS_EXT_NONE,
-                                             cancellable, error))
+                                             list_refs_flags, cancellable, error))
         return FALSE;
 
       ret_contents = g_strdup (g_hash_table_lookup (refs, ref));
index d24077c94b1ef2caf2c337e8ed8086c8217cb264..afa33155b37f23d3bdc12b7da3563b36eb4b3cf2 100644 (file)
@@ -465,9 +465,11 @@ gboolean      ostree_repo_resolve_rev (OstreeRepo  *self,
 /**
  * OstreeRepoResolveRevExtFlags:
  * @OSTREE_REPO_RESOLVE_REV_EXT_NONE: No flags.
+ * @OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY: Exclude remote and mirrored refs. Since: 2019.2
  */
 typedef enum {
   OSTREE_REPO_RESOLVE_REV_EXT_NONE = 0,
+  OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY = (1 << 0),
 } OstreeRepoResolveRevExtFlags;
 
 _OSTREE_PUBLIC